from zai import ZhipuAiClient
# from openai import OpenAI
import numpy as np


client = ZhipuAiClient(
    base_url="https://api.siliconflow.cn/v1/",
    api_key="sk-knraanmfzbmiaqemqzsfxusqzvrcxuuioomrdknougvokjkl"
)

documents = [
    "你好",
    "这部电影既刺激又令人兴奋。",
    "阅读书籍是扩展知识的好方法。"
]

response = client.embeddings.create(
    model="BAAI/bge-large-zh-v1.5",
    input=documents,
    dimensions=1024
)

v1 = response.data[0].embedding
v2 = response.data[1].embedding
v3 = response.data[2].embedding

def cos_smi(a, b):
    dot_product = np.dot(a, b)
    norm_v1 = np.linalg.norm(a)
    norm_v2 = np.linalg.norm(b)
    if norm_v1 == 0 or norm_v2 == 0:
        return 0.0  # 避免除以零
    return dot_product / (norm_v1 * norm_v2)



print("(v2, v1)", cos_smi(v2, v1))
print("(v2, v3)", cos_smi(v2, v3))
